<!--title-->
<div class="mnav1">
	<div class="m_nav">
		<div class="nav_left">
			<em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
		</div>
	</div>
</div>

<div class="content-table2">
<div class="content-table-title"><?=$this->title?></div>
<div class="form-edit-task">

<form action="/dcc/companies-edit-submit" method="post" name="form1" onsubmit="submitform(this);return false;">
<table border="0" width="100%">
	<tr>
		<td align="right">店铺名称：</td>
		<td align="left">&nbsp;<input type="text" placeholder="店铺名称" name="company_name" id="company_name" autocomplete="off" onkeyup="SearchDealer(this)" value="<?=$this->data['company_name']?>" style="width: 300px"><font color="red"> *</font></td>
	</tr>
    <tr>
        <td align="right">车智汇通Dealer ID：</td>
        <td align="left">&nbsp;<input type="text" name="czht_dealer_id" id="czht_dealer_id" autocomplete="off" value="<?=$this->data['czht_dealer_id']?>" style="width: 300px"><font color="red"> * 填写公司名称自动匹配</font></td>
    </tr>
	 <tr>
        <td align="right">起始日：</td>
        <td align="left">&nbsp;<input type="text" name="start_date" id="start_date" style="width: 100px"></td>
    </tr>
	<tr>
		<td align="right">到期日：</td>
		<td align="left">&nbsp;<input type="text" name="expired_date" id="expired_date" value="<?=$this->data['expired_date']?>" style="width: 100px" autocomplete="off"></td>
	</tr>
	<tr>
		<td align="right">运营状态：</td>
		<td align="left">&nbsp;<select name="status" id="status">
					<option value="1" <?php if($this->data['status']):?>selected="selected"<?php endif;?>>运营中</option>
					<option value="0" <?php if(!$this->data['status']):?>selected="selected"<?php endif;?>>已关店</option>
				</select><font color="red"> *</font>
		</td>
	</tr>
	<tr>
		<td align="right">外显号码：</td>
		<td align="left">&nbsp;<input type="text" placeholder="外显号码" name="client_display_number" id="client_display_number" value="<?=$this->data['client_display_number']?>" style="width: 300px"><font color="red"> 如果留空，无法使用电话条</font></td>
	</tr>
	<tr>
		<td align="right">营业时间开始：</td>
		<td align="left">&nbsp;<input type="text" placeholder="营业时间开始" name="biz_start" id="biz_start" value="<?=$this->biz_time['biz_start']?>" style="width: 300px"><font color="red"> * 必填</font></td>
	</tr>
	<tr>
		<td align="right">营业时间结束：</td>
		<td align="left">&nbsp;<input type="text" placeholder="营业时间结束" name="biz_end" id="biz_end" value="<?=$this->biz_time['biz_end']?>" style="width: 300px"><font color="red"> * 必填</font></td>
	</tr>
	<tr>
		<td align="right">首呼任务期限：</td>
		<td align="left">&nbsp;<input type="text" placeholder="首呼任务期限" name="period" id="period" value="<?=$this->period['period']?>"><font color="red"> * 必填，小时</font></td>
	</tr>
	<tr>
		<td align="right">经理姓名：</td>
		<td align="left">&nbsp;<input type="text" placeholder="经理姓名" name="user_name" id="user_name" value="<?=$this->data['user_name']?>"></td>
	</tr>
	<tr>
		<td align="right">经理手机：</td>
		<td align="left">&nbsp;<input type="text" placeholder="经理手机" name="cellphone" id="cellphone" value="<?=$this->data['cellphone']?>"><font color="red"> * 登录名，必填</font></td>
	</tr>
	<tr>
		<td align="right">经理登录密码：</td>
		<td align="left">&nbsp;<input type="text" placeholder="经理登录密码" name="pwd" id="pwd" autocomplete="off"><font color="red"> 无需修改请留空</font></td>
	</tr>
	<tr>
		<td align="right">负责运营：</td>
		<td align="left">&nbsp;<input type="text" placeholder="负责运营" name="staff_name" id="staff_name" value="<?=$this->data['staff_name']?>" style="width: 300px"></td>
	</tr>
    <tr>
        <td align="right">品牌：</td>
        <td align="left">&nbsp;<input type="text" placeholder="品牌" name="dealer_brand" id="dealer_brand" value="<?=$this->data['dealer_brand']?>" style="width: 300px"><font color="red"> * 品牌，必填</font></td>
    </tr>
    <tr>
        <td align="right">经销商地址：</td>
        <td align="left">&nbsp;<input type="text" placeholder="经销商地址" name="dealer_address" id="dealer_address" value="<?=$this->data['dealer_address']?>" style="width: 300px"><font color="red"> * 经销商地址，必填</font></td>
    </tr>
	<tr>
		<td align="right">厂商1：</td>
		<td align="left">&nbsp;<select name="factory_id_1" id="factory_id_1">
					<option value=""></option>
					<?php foreach($this->factories as $factory_id => $factory_name):?>
					<option value="<?=$factory_id?>" <?php if(isset($this->fac[0]) && $factory_id==$this->fac[0]):?>selected="selected"<?php endif;?>><?=$factory_name?></option>
					<?php endforeach;?>
				</select>
		</td>
	</tr>
	<tr>
		<td align="right">厂商2：</td>
		<td align="left">&nbsp;<select name="factory_id_2" id="factory_id_2">
					<option value=""></option>
					<?php foreach($this->factories as $factory_id => $factory_name):?>
					<option value="<?=$factory_id?>" <?php if(isset($this->fac[1]) && $factory_id==$this->fac[1]):?>selected="selected"<?php endif;?>><?=$factory_name?></option>
					<?php endforeach;?>
				</select>
		</td>
	</tr>
	<tr>
		<td align="right">厂商3：</td>
		<td align="left">&nbsp;<select name="factory_id_3" id="factory_id_3">
					<option value=""></option>
					<?php foreach($this->factories as $factory_id => $factory_name):?>
					<option value="<?=$factory_id?>" <?php if(isset($this->fac[2]) && $factory_id==$this->fac[2]):?>selected="selected"<?php endif;?>><?=$factory_name?></option>
					<?php endforeach;?>
				</select>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center"><br><br>
			<input type="hidden" name="company_id" value="<?=$this->company_id?>" />
			<input type="button" class="buttonlong" value="提交审核" onclick="submitform();return false;" />
		</td>
	</tr>
</table>
<br /><br />
</form>
</div>
<br/><br/>
</div>

<script>
<?php if($this->msg):?>
alert("<?=$this->msg?>, 信息提交失败, 请修改后再次提交。");
<?php endif;?>

function submitform() 
{
    if($('#czht_dealer_id').val().length == 0){
        $('#czht_dealer_id').focus();
        $('#czht_dealer_id').attr('placeholder','请填写车智汇通Dealer ID');
        alert('车智汇通Dealer ID不能为空');
        return false;
    }

	if( document.form1.company_name.value.length == 0 )
	{
		alert("店铺名称不能为空。");
		return false;
	}else if( document.form1.cellphone.value.length == 0 )
	{
		alert("经理手机不能为空。");
		return false;
	}else if (document.form1.dealer_brand.value.length == 0) {
        alert("品牌不能为空。");
        return false;
    }else if( document.form1.dealer_address.value.length == 0 ) {
        alert("经销商地址不能为空。");
        return false;
    }else{
		$.ajax({
			type: "post",
			url : "/ajax/cellphone-available",
			dataType:'json',
            async:false,
			data: {
					'cellphone':document.form1.cellphone.value,
					'user_id':<?=$this->data['user_id']?>
				  },
				success: function(json){
					if(json.result == 1) {
                        form1.submit();
                    }else{
						alert("系统中已存在相同手机号，请更换");
						return false;
					}
			}
		});
	}
}

$(function() {
	$( "#expired_date" ).datepicker({ dateFormat: 'yy-mm-dd'});
	$( "#start_date" ).datepicker({ dateFormat: 'yy-mm-dd'}).datepicker("setDate", "<?=$this->data['start_date']?>");
});

function SearchDealer(element)
{
    var userName = element.value;
    if(userName) {
        $.ajax({
            url: "/ajax/search-dealer-id",
            dataType: 'json',
            type: 'get',
            data: {
                name: userName
            },
            success: function (e)
            {
                $("#czht_dealer_id").val(e.id)
            }
        })
    }

}

</script>
